package com.ct.controller;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.ct.entity.po.Reimbursement;
import com.ct.entity.query.ReimbursementQuery;
import com.ct.entity.vo.ResponseVO;
import com.ct.factory.ReimbursementFactory;
import com.ct.service.ReimbursementService;

import jakarta.annotation.Resource;
import jakarta.validation.constraints.NotEmpty;

/**
 * 报销表 Controller
 */
@RestController("reimbursementController")
@RequestMapping("/reimbursement")
public class ReimbursementController extends ABaseController {

    @Resource
    private ReimbursementService reimbursementService;

    /**
     * 根据条件分页查询
     */
    @RequestMapping("/loadDataList")
    public ResponseVO loadDataList(ReimbursementQuery query) {
        return getSuccessResponseVO(reimbursementService.findListByPage(query));
    }

    /**
     * 新增
     */
    @RequestMapping("/addReimbursement")
    public ResponseVO add(@NotEmpty Date applyDate, @NotEmpty BigDecimal foodCost, @NotEmpty BigDecimal transportCost,
            @NotEmpty BigDecimal hotelCost, @NotEmpty String detail, @NotEmpty int travelId) {
        // Reimbursement reimbursement = new
        // Reimbursement(null,foodCost,transportCost,hotelCost,applyDate,detail,travelId);
        Reimbursement reimbursement = ReimbursementFactory.createReimbursement(foodCost, transportCost, hotelCost,
                applyDate, detail, travelId);
        System.out.println(reimbursement);
        reimbursementService.add(reimbursement);
        return getSuccessResponseVO(null);
    }

    /**
     * 批量新增
     */
    @RequestMapping("/addBatch")
    public ResponseVO addBatch(@RequestBody List<Reimbursement> listBean) {
        reimbursementService.addBatch(listBean);
        return getSuccessResponseVO(null);
    }

    /**
     * 批量新增/修改
     */
    @RequestMapping("/addOrUpdateBatch")
    public ResponseVO addOrUpdateBatch(@RequestBody List<Reimbursement> listBean) {
        reimbursementService.addBatch(listBean);
        return getSuccessResponseVO(null);
    }

    /**
     * 根据ReimbursementId查询对象
     */
    @RequestMapping("/getReimbursementByReimbursementId")
    public ResponseVO getReimbursementByReimbursementId(Integer reimbursementId) {
        return getSuccessResponseVO(reimbursementService.getReimbursementByReimbursementId(reimbursementId));
    }

    /**
     * 根据ReimbursementId修改对象
     */
    @RequestMapping("/updateReimbursementByReimbursementId")
    public ResponseVO updateReimbursementByReimbursementId(Reimbursement bean, Integer reimbursementId) {
        reimbursementService.updateReimbursementByReimbursementId(bean, reimbursementId);
        return getSuccessResponseVO(null);
    }

    /**
     * 根据ReimbursementId删除
     */
    @RequestMapping("/deleteReimbursementByReimbursementId")
    public ResponseVO deleteReimbursementByReimbursementId(Integer reimbursementId) {
        reimbursementService.deleteReimbursementByReimbursementId(reimbursementId);
        return getSuccessResponseVO(null);
    }

    @PostMapping("/getReimbursementByTravelIdList")
    public List<Reimbursement> getReimbursementByTravelIdList(@RequestBody List<Integer> travelIdList) {
        return reimbursementService.getReimbursementByTravelIdList(travelIdList);
    }

    /**
     * 根据TravelId查询一个Reimbursement
     */
    @RequestMapping("/getReimbursementByTravelId")
    public ResponseVO getReimbursementByTravelId(@RequestParam Integer travelId) {
        return getSuccessResponseVO(reimbursementService.getReimbursementByTravelId(travelId));
    }

}